package com.woniuxy.intellihome.controller.ucenter;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.intellihome.entity.*;
import com.woniuxy.intellihome.service.*;
import com.woniuxy.intellihome.utils.UtilsTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-08-11
 */
@Controller("ucenter/review")
@RequestMapping("ucenter/review")
public class ReviewController {
    @Autowired(required = true)
    private VReviewService vReviewService;
    @Autowired(required = true)
    private ReviewService reviewService;
    //展示收藏夹列表
    @GetMapping("list")
    public String list(Integer current, Model model, HttpSession session, VReview vReview) {
        User user = (User) session.getAttribute("user1");
        if(vReview == null){
            vReview = new VReview();
        }
        QueryWrapper<VReview> queryWrapper = new QueryWrapper<>();
        if (vReviewService.getAllReviewByUserId(user.getId())!=null) {
            queryWrapper.eq("user_id",user.getId());
        }
        //分页跳转
        if (current == null) {
            current = 1;
        }
        Page<VReview> page = new Page<>(current, 2);
        page = vReviewService.page(page,queryWrapper);
        System.out.println("当前页"+page.getCurrent());
        System.out.println("page里的内容"+page.getRecords());
        model.addAttribute("page", page);
        System.out.println("page========"+page);
        return "ucenter/user_review";
    }

}

